<?php
/**
 * Created by PhpStorm.
 * User: Administrator
 * Date: 2018/4/4
 * Time: 11:09
 */
//针对于用户的数据的封装，继承，多态
//面向对线的编程方法
class adminDb
{
    //用户登录方法
    public function login($name, $pass)
    {
        $sql = "select * from user where name='$name' and pass='$pass'";
        $dbConn = new DbCon();
        return $dbConn->query($sql);
    }

    //新增bug的方法
    public function add_bug($product, $platfrom, $person, $title, $content, $newName, $status, $version, $addtime)
    {
        $sql = "insert into bug (product,platfrom,person,title,content,newName,status,version,addtime) values('$product','$platfrom','$person','$title','$content','$newName','$status','$version','$addtime')";
        $dbCon = new DbCon();
        return $dbCon->add($sql);


    }

    //编辑bug的方法
    public function edit_bug($id, $product, $platfrom, $person, $title, $desc, $content, $url, $newName, $status, $addtime)
    {
        $sql = "update bug set product='$product',platfrom='$platfrom',person='$person',title='$title',desction='$desc',content='$content', image='$url',newName='$newName',status='$status',addtime='$addtime' where id='$id'";
        $dbConn = new DbCon();
        return $dbConn->modify($sql);
    }

    //编辑状态
    public function edit_status($id, $status)
    {
        $sql = "update bug set status='$status'where id='$id'";
        $dbCoun = new DbCon();
        return $dbCoun->modify($sql);


    }

    //删除bug
    public function del_bug($id)
    {
        $sql = "delete from bug where id='$id'";
        $dbCoun = new DbCon();
        return $dbCoun->delete($sql);

    }

    //创建人查询
    public function query_bug_user($name)
    {
        $sql = "select * from bug where newName='$name' or person='$name'";
        $dbCoun = new DbCon();
        return $dbCoun->query($sql);


    }

    public function query_bug_user_page($name, $firstNum, $lastNum)
    {
        $sql = "select * from bug where newName='$name'or person='$name' order by id desc limit $firstNum,$lastNum";
        $dbCoun = new DbCon();
        return $dbCoun->query($sql);

    }

    public function query_bug_page_user($name, $firstNum, $lastNum)
    {

        $sql = "select * from bug where newName='$name' or person='$name' order by id desc limit $firstNum,$lastNum";
        $dbCoun = new DbCon();
        return $dbCoun->query($sql);

    }

    //分页查询
    public function query_page($firstNum, $lastNum, $product, $person, $status)
    {
        $sql = "select *b from bug where product='$product'and person='$person'and status='$status' order by id desc limit $firstNum,$lastNum";
        $dbCoun = new DbCon();
        return $dbCoun->query($sql);
    }

    //查询所有的bug数据
    public function query_bug()
    {
        $sql = "select * from bug order by id desc ";
        $dbCoun = new DbCon();
        return $dbCoun->query($sql);

    }

    public function query_bug_user1($name)
    {

        $sql = "select * from bug where person='$name' or newName='$name'";
        $dbCoun = new DbCon();
        return $dbCoun->query($sql);
    }

    public function query_bug_user11($name)
    {
        $sql = "select * from bug where person='$name' and newName='$name'";
        $dbCoun = new DbCon();
        return $dbCoun->query($sql);
    }

    public function query_bug_page_user1($name, $firstNum, $lastNum)
    {
        $sql = "select * from bug where newName='$name' order by id desc limit $firstNum,$lastNum ";
        $dbCoun = new DbCon();
        return $dbCoun->query($sql);

    }

    public function query_bug_page($firstNum, $lastNum)
    {
        $sql = "select * from bug order by id desc limit $firstNum,$lastNum ";
        $dbCoun = new DbCon();
        return $dbCoun->query($sql);

    }

    //根据id查询对应的bug
    public function queryBug_id($id)
    {
        $sql = "select * from bug where id='$id'";
        $dbCoun = new DbCon();
        return $dbCoun->query($sql);

    }

    //筛选查询数据-产品
    public function query_bug_Product($product)
    {
        $sql = "select * from bug where product='$product'";
        $dbCoun = new DbCon();
        return $dbCoun->query($sql);
    }

    public function query_bug_Product1($name, $product)
    {
        $sql = "select * from bug where product='$product'and (person='$name'or newName='$name')";
        $dbCoun = new DbCon();
        return $dbCoun->query($sql);
    }

    public function query_bug_Product_page($firstNum, $lastNum, $product)
    {
        $sql = "select * from bug  where product='$product' order by id desc limit $firstNum,$lastNum";
        $dbCoun = new DbCon();
        return $dbCoun->query($sql);
    }

    public function query_bug_Product_page1($name, $firstNum, $lastNum, $product)
    {
        $sql = "select * from bug where product='$product'and (person='$name' or newName='$name') order by id desc limit $firstNum,$lastNum";
        $dbCoun = new DbCon();
        return $dbCoun->query($sql);
    }

    //筛选查询数据-负责人
    public function query_bug_person($person)
    {
        $sql = "select * from bug where person='$person'";
        $dbCoun = new DbCon();
        return $dbCoun->query($sql);
    }

    //筛选作者
    public function query_bug_auther($status)
    {

        $sql = "select * from bug where status='$status'";
        $dbCoun = new DbCon();
        return $dbCoun->query($sql);
    }

    public function query_bug_person1($name, $person)
    {
        $sql = "select * from bug where person='$person'and (person='$name' or newName='$name')";
        $dbCoun = new DbCon();
        return $dbCoun->query($sql);
    }

    public function query_bug_person_page($firstNum, $lastNum, $person)
    {
        $sql = "select * from bug where person='$person'order by id desc limit $firstNum,$lastNum";
        $dbCoun = new DbCon();
        return $dbCoun->query($sql);

    }

    public function query_bug_person_page1($name, $firstNum, $lastNum, $person)
    {
        $sql = "select * from bug where person='$person'and (person='$name' or newName='$name') order by id desc limit $firstNum,$lastNum";
        $dbCoun = new DbCon();
        return $dbCoun->query($sql);

    }

    //筛选查询数据-状态
    public function query_bug_status($status)
    {
        $sql = "select * from bug where status='$status'";
        $dbCoun = new DbCon();
        return $dbCoun->query($sql);
    }

    public function query_bug_status_page($firstNum, $lastNum, $status)
    {
        $sql = "select * from bug where status='$status'order by id desc limit $firstNum,$lastNum";
        $dbCoun = new DbCon();
        return $dbCoun->query($sql);
    }

    public function query_bug_auther_page($firstNum, $lastNum, $auther)
    {
        $sql = "select * from bug where newName='$auther'order by id desc limit $firstNum,$lastNum";
        $dbCoun = new DbCon();
        return $dbCoun->query($sql);
    }

    public function query_bug_status1($name, $status)
    {
        $sql = "select * from bug where status='$status'and (person='$name' or newName='$name')";
        $dbCoun = new DbCon();
        return $dbCoun->query($sql);
    }

    public function query_bug_status_page1($name, $firstNum, $lastNum, $status)
    {
        $sql = "select * from bug where status='$status'and (person='$name' or newName='$name')order by id desc limit $firstNum,$lastNum";
        $dbCoun = new DbCon();
        return $dbCoun->query($sql);
    }

    //筛选查询数据-列外条件
    public function query_bug_all($product, $person, $status)
    {
        $sql = "select * from bug where product='$product' and person='$person' and status='$status'";
        $dbCoun = new DbCon();
        return $dbCoun->query($sql);
    }

    public function query_bug_all_page($firstNum, $lastNum, $status, $person, $product)
    {
        $sql = "select * from bug where product='$product' and person='$person' and status='$status'order by id desc limit $firstNum,$lastNum";
        $dbCoun = new DbCon();
        return $dbCoun->query($sql);

    }

    public function query_bug_all1($name, $product, $person, $status)
    {
        $sql = "select * from bug where product='$product' and person='$person' and status='$status'and (person='$name' or newName='$name')";
        $dbCoun = new DbCon();
        return $dbCoun->query($sql);
    }

    public function query_bug_all_page1($name, $firstNum, $lastNum, $status, $person, $product)
    {
        $sql = "select * from bug where product='$product' and person='$person' and status='$status'and (person='$name' or newName='$name') order by id desc limit $firstNum,$lastNum";
        $dbCoun = new DbCon();
        return $dbCoun->query($sql);

    }

    //product,person
    public function query_bug_pp($product, $person)
    {
        $sql = "select * from bug where product='$product' and person='$person'";
        $dbCoun = new DbCon();
        return $dbCoun->query($sql);
    }

    //auther,status
    public function query_bug_sa($status, $auther)
    {
        $sql = "select * from bug where status='$status' and newName='$auther'";
        $dbCoun = new DbCon();
        return $dbCoun->query($sql);
    }

    //product,status
    public function query_bug_pa($product, $auther)
    {
        $sql = "select * from bug where product='$product' and newName='$auther'";
        $dbCoun = new DbCon();
        return $dbCoun->query($sql);
    }

    //auther,status
    public function query_bug_ppa($person, $auther)
    {
        $sql = "select * from bug where person='$person' and newName='$auther'";
        $dbCoun = new DbCon();
        return $dbCoun->query($sql);
    }

    public function query_bug_spa($status, $product, $auther)
    {

        $sql = "select * from bug where status='$status' and newName='$auther'and product='$product'";
        $dbCoun = new DbCon();
        return $dbCoun->query($sql);
    }

    public function query_bug_sppa($status, $person, $auther)
    {
        $sql = "select * from bug where status='$status' and newName='$auther'and person='$person'";
        $dbCoun = new DbCon();
        return $dbCoun->query($sql);
    }

    public function query_bug_pppa($person, $product, $auther)
    {
        $sql = "select * from bug where person='$person' and newName='$auther'and product='$product'";
        $dbCoun = new DbCon();
        return $dbCoun->query($sql);
    }

    public function query_bug_sppall($status, $product, $person, $auther)
    {
        $sql = "select * from bug where person='$person' and newName='$auther'and product='$product'and status='$status'";
        $dbCoun = new DbCon();
        return $dbCoun->query($sql);

    }

    public function query_bug_spa_page($firstNum, $lastNum, $status, $product, $auther)
    {

        $sql = "select * from bug where product='$product' and status='$status'and newName='$auther' order by id desc limit $firstNum,$lastNum";
        $dbCoun = new DbCon();
        return $dbCoun->query($sql);
    }

    public function query_bug_sppa_page($firstNum, $lastNum, $status, $person, $auther)
    {

        $sql = "select * from bug where person='$person' and status='$status' and newName='$auther' order by id desc limit $firstNum,$lastNum";
        $dbCoun = new DbCon();
        return $dbCoun->query($sql);
    }

    public function query_bug_pppa_page($firstNum, $lastNum, $person, $product, $auther)
    {

        $sql = "select * from bug where person='$person' and product='$product' and newName='$auther' order by id desc limit $firstNum,$lastNum";
        $dbCoun = new DbCon();
        return $dbCoun->query($sql);
    }

    public function query_bug_spall_page($firstNum, $lastNum, $status, $product, $person, $auther)
    {

        $sql = "select * from bug where person='$person' and product='$product' and newName='$auther'and status='$status' order by id desc limit $firstNum,$lastNum";
        $dbCoun = new DbCon();
        return $dbCoun->query($sql);
    }

    public function query_bug_pp_page($firstNum, $lastNum, $person, $product)
    {
        $sql = "select * from bug where product='$product' and person='$person' order by id desc limit $firstNum,$lastNum";
        $dbCoun = new DbCon();
        return $dbCoun->query($sql);

    }

    public function query_bug_sa_page($firstNum, $lastNum, $status, $auther)
    {
        $sql = "select * from bug where status='$status' and newName='$auther' order by id desc limit $firstNum,$lastNum";
        $dbCoun = new DbCon();
        return $dbCoun->query($sql);

    }

    public function query_bug_pa_page($firstNum, $lastNum, $product, $auther)
    {
        $sql = "select * from bug where product='$product' and newName='$auther' order by id desc limit $firstNum,$lastNum";
        $dbCoun = new DbCon();
        return $dbCoun->query($sql);

    }

    public function query_bug_ppa_page($firstNum, $lastNum, $person, $auther)
    {
        $sql = "select * from bug where person='$person' and newName='$auther' order by id desc limit $firstNum,$lastNum";
        $dbCoun = new DbCon();
        return $dbCoun->query($sql);

    }


    public function query_bug_pp1($name, $product, $person)
    {
        $sql = "select * from bug where product='$product' and person='$person'and(person='$name' or newName='$name')";
        $dbCoun = new DbCon();
        return $dbCoun->query($sql);
    }

    public function query_bug_pp_page1($name, $firstNum, $lastNum, $person, $product)
    {
        $sql = "select * from bug where product='$product' and person='$person'and(person='$name' or newName='$name')order by id desc limit $firstNum,$lastNum";
        $dbCoun = new DbCon();
        return $dbCoun->query($sql);

    }

    //product status
    public function query_bug_ps($product, $status)
    {
        $sql = "select * from bug where product='$product' and status='$status'";
        $dbCoun = new DbCon();
        return $dbCoun->query($sql);
    }

    public function query_bug_ps_page($firstNum, $lastNum, $status, $product)
    {

        $sql = "select * from bug where product='$product' and status='$status'order by id desc limit $firstNum,$lastNum";
        $dbCoun = new DbCon();
        return $dbCoun->query($sql);
    }

    public function query_bug_ps1($name, $product, $status)
    {
        $sql = "select * from bug where product='$product' and status='$status'and(person='$name' or newName='$name')";
        $dbCoun = new DbCon();
        return $dbCoun->query($sql);
    }

    public function query_bug_ps_page1($name, $firstNum, $lastNum, $status, $product)
    {

        $sql = "select * from bug where product='$product' and status='$status' and(person='$name' or newName='$name')order by id desc limit $firstNum,$lastNum";
        $dbCoun = new DbCon();
        return $dbCoun->query($sql);
    }

    //person status
    public function query_bug_sp($status, $person)
    {
        $sql = "select * from bug where person='$person' and status='$status'";
        $dbCoun = new DbCon();
        return $dbCoun->query($sql);

    }

    public function query_bug_sp_page($firstNum, $lastNum, $status, $person)
    {
        $sql = "select * from bug where person='$person' and status='$status'order by id desc limit $firstNum,$lastNum";
        $dbCoun = new DbCon();
        return $dbCoun->query($sql);

    }

    public function query_bug_sp1($name, $status, $person)
    {
        $sql = "select * from bug where person='$person' and status='$status'and(person='$name' or newName='$name')";
        $dbCoun = new DbCon();
        return $dbCoun->query($sql);

    }

    public function query_bug_auther1($auther)
    {
        $sql = "select * from bug where newName='$auther'";
        $dbCoun = new DbCon();
        return $dbCoun->query($sql);
    }


    public function query_bug_sp_page1($name, $firstNum, $lastNum, $status, $person)
    {
        $sql = "select * from bug where person='$person' and status='$status' and(person='$name' or newName='$name')order by id desc limit $firstNum,$lastNum";
        $dbCoun = new DbCon();
        return $dbCoun->query($sql);

    }

    //查询用户
    public function query_user()
    {
        $sql = "select id,card,desction,name,addtime from user ";
        $dbCoun = new DbCon();
        return $dbCoun->query($sql);

    }

    //删除用户
    public function del_user($id)
    {
        $sql = "delete from user where id='$id'";
        $dbCoun = new DbCon();
        return $dbCoun->delete($sql);

    }

    //删除项目
    public function del_project($id)
    {
        $sql = "delete from project where id='$id'";
        $dbCoun = new DbCon();
        return $dbCoun->delete($sql);
    }

    //用户name
    public function query_userName($name)
    {
        $sql = "select * from user where name='$name'";
        $dbCoun = new DbCon();
        return $dbCoun->query($sql);

    }

    //用户name
    public function query_user_id($userName)
    {
        $sql = "select * from user where name='$userName'";
        $dbCoun = new DbCon();
        return $dbCoun->query($sql);

    }

    //根据id查询用户
    public function select_user_id($id)
    {
        $sql = "select * from user where id='$id'";
        $dbCoun = new DbCon();
        return $dbCoun->query($sql);

    }

    //查询项目名是否重复
    public function query_project_name($project)
    {
        $sql = "select * from project where name='$project'";
        $dbCoun = new DbCon();
        return $dbCoun->query($sql);
    }

    //新增用户
    public function add_user($userName, $password, $card, $desc, $addtime)
    {
        $sql = "insert into user (name,pass,card,desction,addtime) values('$userName','$password','$card','$desc','$addtime')";
        $dbCon = new DbCon();
        return $dbCon->add($sql);

    }

    //新增项目
    public function add_project($project, $addtime)
    {
        $sql = "insert into project(name,ctime) values('$project','$addtime')";
        $dbCon = new DbCon();
        return $dbCon->add($sql);

    }

    //修改用户
    public function updataUser($id, $name, $password, $card, $desc, $addtime)
    {
        $sql = "update user set name='$name',pass='$password',card='$card',desction='$desc',addtime='$addtime' where id='$id'";
        $dbConn = new DbCon();
        return $dbConn->modify($sql);

    }

    //修改负责人
    public function updatePerson($id, $person, $reason)
    {
        $sql = "update bug set person='$person',reason='$reason' where id='$id'";
        $dbCoun = new DbCon();
        return $dbCoun->modify($sql);


    }

//查询项目
    public function query_project()
    {
        $sql = "select * from project";
        $dbCoun = new DbCon();
        return $dbCoun->query($sql);


    }

    //查询auther
    public function query_auther($auther)
    {
        $sql = "select * from bug where newName='$auther'";
        $dbCoun = new DbCon();
        return $dbCoun->query($sql);


    }

    public function query_auther_page($auther, $firstNum, $lastNum)
    {
        $sql = "select * from bug  where newName='$auther' order by id desc limit $firstNum,$lastNum";
        $dbCoun = new DbCon();
        return $dbCoun->query($sql);
    }

    //查询未修改和已修改
    public function query_status_nr($not_change, $revised, $name)
    {
        $sql = "select * from bug where (status='$not_change' and person='$name') or(status='$revised' and newName='$name')";
        $dbCoun = new DbCon();
        return $dbCoun->query($sql);
    }

    public function query_status_nr_page($not_change, $revised, $name, $firstNum, $lastNum)
    {
        $sql = "select * from bug where (status='$not_change' and person='$name') or(status='$revised' and newName='$name') order by id desc limit $firstNum,$lastNum";
        $dbCoun = new DbCon();
        return $dbCoun->query($sql);
    }

    //新增评论
    public function add_comment($user_id, $bug_id, $series, $content, $addtime)
    {
        $sql = "insert into comment(bug_id,user_id,content,series,addtime) values('$bug_id','$user_id','$content','$series','$addtime')";
        $dbCon = new DbCon();
        return $dbCon->add($sql);

    }

    //查询评论
    public function queryComment_id($id)
    {

        $sql = "select * from comment ,user where comment.user_id=user.id and comment.bug_id='$id'";
        $dbCoun = new DbCon();
        return $dbCoun->query($sql);

    }

    //根据时间查询bug
    public function query_bug_time($s, $e, $name)
    {
        $sql = "select id from bug where (addtime>='$s' or addtime<='$e') and (person='$name' or newName='$name')";
        $dbCoun = new DbCon();
        return $dbCoun->query($sql);
    }

    public function query_bug_time_page($s, $e, $name, $firstNum, $lastNum)
    {
        $sql = "select * from bug where addtime>='$s' and  addtime<='$e' and (person='$name' or newName='$name')order by id desc limit $firstNum,$lastNum";
        $dbCoun = new DbCon();
        return $dbCoun->query($sql);

    }

}
